package com.example.park2301.fangke

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.lib_base.mvvm.BaseActivity
import com.example.park2301.R
import com.example.park2301.databinding.ActivityFkBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@AndroidEntryPoint
@Route(path = "/app/FkActivity")
class FkActivity : BaseActivity<ActivityFkBinding,FkViewModel>() {
    private val fkAdapter by lazy { FkAdapter() }
    override fun initView() {
        binding.lfRv2.apply {
            adapter=fkAdapter
            layoutManager=LinearLayoutManager(this@FkActivity)
        }
        lifecycleScope.launch {
            vm.getFang("","类型").collect(){
                fkAdapter.submitData(it)
            }
        }
        binding.lfSearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener{
            override fun onQueryTextSubmit(query: String?): Boolean {
                lifecycleScope.launch {
                    vm.getFang(query!!,"搜索").collect{
                        fkAdapter.submitData(it)
                    }
                }
                return true
            }

            override fun onQueryTextChange(newText: String?): Boolean {
                lifecycleScope.launch {
                    vm.getFang(newText!!,"类型").collect(){
                        fkAdapter.submitData(it)
                    }
                }
               return true
            }

        })
    }

    override fun initData() {

    }

}